﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.IO.IsolatedStorage;
using Microsoft.Phone.Tasks;

namespace BuyTrainTicket
{
    public partial class Setting : PhoneApplicationPage
    {
        public Setting()
        {
            InitializeComponent();
            IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
            String username;
            settings.TryGetValue<String>("username", out username);
            if (username != null)
            {
                text_username.Text = username;
            }
            String password;
            settings.TryGetValue<String>("password", out password);
            if (password != null)
            {
                text_password.Password = password;
            }
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            String username = text_username.Text;
            String password = text_password.Password;
            if (username == null || password == null || username.Equals("") || password.Equals(""))
            {
                MessageBox.Show("用户名为空。");
                return;
            }
            IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
            settings["username"] = username;
            settings["password"] = password;
            settings.Save();
            Util.savePushUser(username);
        }

        private void TextBlock_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
        {
            WebBrowserTask task = new WebBrowserTask();
            task.Uri = new Uri("https://dynamic.12306.cn/otsweb/");
            task.Show();
        }
    }
}